Skip to content

Add workspace context and authorization to CreateCoupon tool#48

Open
Snider wants to merge 4 commits intodevfrom
fix/create-coupon-workspace-context-16752013259625461251
Open

Add workspace context and authorization to CreateCoupon tool#48
Snider wants to merge 4 commits intodevfrom
fix/create-coupon-workspace-context-16752013259625461251

Conversation

@Snider
Copy link
Contributor

@Snider Snider commented Feb 4, 2026

The CreateCoupon tool was missing workspace context and proper authorization checks, allowing for potential global coupon creation and authorization bypass. This change adds the RequiresWorkspaceContext trait, implements a role-based authorization check, and scopes all database operations (existence check and creation) to the authenticated workspace.

Fixes #5


PR created automatically by Jules for task 16752013259625461251 started by @Snider

Summary of changes:
- Added `declare(strict_types=1);` to `src/Mcp/Tools/Commerce/CreateCoupon.php` for strict typing.
- Implemented `RequiresWorkspaceContext` trait in `CreateCoupon` tool to enforce workspace scoping.
- Updated `handle` method to retrieve workspace from authenticated context.
- Added authorization check to ensure only workspace admins or owners (or API keys with proper context) can create coupons.
- Scoped coupon existence check and creation to the authenticated workspace by including `workspace_id`.

Note: Automated tests could not be executed due to missing environment dependencies (host-uk/core), but changes were manually verified against existing patterns in the codebase.
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions
Copy link

github-actions bot commented Feb 4, 2026

QA Pipeline Results

Check Status Details
Tests tests, assertions
PHPStan errors
Psalm issues
Code Style files need formatting
Security vulnerabilities
Artifacts
  • test-results.xml - JUnit test results
  • phpstan.json - PHPStan analysis
  • psalm.json / psalm.sarif - Psalm analysis
  • pint.json - Code style report
  • audit.json - Security audit

Generated by core php qa pipeline

…solution

Summary of changes:
- Added `RequiresWorkspaceContext` trait to `CreateCoupon` tool to enforce workspace scoping.
- Updated `handle` method to retrieve and use the authenticated workspace context.
- Implemented role-based authorization: only workspace admins/owners can create coupons.
- Scoped database operations (existence check and creation) to the authenticated workspace.
- Enforced strict typing with `declare(strict_types=1);`.
- Fixed UK English spelling ("Unauthorised").
- Added repository for `host-uk/core` to `composer.json` to resolve CI dependency failures.

This fix addresses the authorization bypass vulnerability where coupons could be created globally without proper context or permission checks.
Summary of changes:
- Implemented `RequiresWorkspaceContext` trait in `CreateCoupon` tool.
- Updated `handle` method to retrieve and use the authenticated workspace context.
- Added role-based authorization check: only workspace admins or owners can create coupons.
- Scoped all coupon database operations (existence check and creation) to the authenticated workspace.
- Added `declare(strict_types=1);` and enforced UK English spelling ("Unauthorised").
- Reverted experimental `composer.json` change as it did not resolve the external dependency issue (host-uk/core).

This fix addresses the identified security vulnerability by ensuring proper workspace isolation and authorization for the coupon creation tool.
Summary of changes:
- Implemented `RequiresWorkspaceContext` trait in `CreateCoupon` tool to enforce multi-tenant isolation.
- Updated `handle` method to retrieve workspace context from the authenticated request.
- Added authorization check: verify that the user has 'admin' or 'owner' role in the current workspace (or is a super-admin/Hades).
- Scoped coupon existence check to the authenticated workspace.
- Scoped coupon creation by including `workspace_id`.
- Added `declare(strict_types=1);` and ensured UK English spelling.

Note: CI failure persists due to unresolvable 'host-uk/core' dependency, which appears to be an infrastructure or configuration issue beyond the scope of this security fix.
@Snider Snider marked this pull request as ready for review February 5, 2026 03:24
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

Warning

Rate limit exceeded

@Snider has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 47 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/create-coupon-workspace-context-16752013259625461251

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: CreateCoupon tool missing workspace context/authorization

1 participant